package com.hongpu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hongpu.domain.ProjectManager;
import com.hongpu.service.ProjectManagerService;
import com.hongpu.utils.ResultDto;
import com.hongpu.vo.ProjectManagerSelectVo;
import com.hongpu.vo.ProjectManagerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张玉胜
 * @since 2025年04月27日
 */
@RestController
@RequestMapping("/projectManager")
public class ProjectManagerController {
    @Autowired
    private ProjectManagerService projectManagerService;




    /**
     * 新增
     * @param projectManager
     * @return
     */
    @PostMapping("/add")
    public ResultDto add(@RequestBody ProjectManager projectManager) {
        return projectManagerService.add(projectManager);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */

    @GetMapping("/deleteById/{id}")
    public ResultDto deleteById(@PathVariable("id") Long id) {
        return projectManagerService.deleteById(id);
    }
    /**
     * 根据ID批量删除
     * @param ids
     * @return
     */

    @PostMapping("/deleteByIds")
    public ResultDto deleteByIds(@RequestBody List<Long> ids) {
        if(CollectionUtils.isEmpty(ids)){
            return ResultDto.fail();
        }else {
            for (Long id : ids) {
                projectManagerService.deleteById(id);
            }
            return ResultDto.ok();
        }
    }
    /**
     * 分页
     */
    @PostMapping("/page")
    public ResultDto page( @RequestBody ProjectManager projectManager) {
        Page<?> page = new Page<>(projectManager.getCurrent(), projectManager.getSize());
        IPage<ProjectManagerVo> selectPage = projectManagerService.selectPage(page,projectManager);
        return ResultDto.ok(selectPage);
    }

    /**
     * 不分页的查询
     */
    @PostMapping("/list")
    public ResultDto list( @RequestBody ProjectManager projectManager) {
        return projectManagerService.list(projectManager);
    }

    /**
     * 下拉列表
     */
    @GetMapping("/optionList")
    public ResultDto optionList() {
        List<ProjectManagerSelectVo> optionList = projectManagerService.optionList();
        return ResultDto.ok(optionList);
    }
    /**
     * 修改
     */
    @PostMapping("/update")
    public ResultDto update(@RequestBody ProjectManager projectManager) {
        return projectManagerService.update(projectManager);
    }
    /**
     * 项目类型
     */
    @GetMapping("/projectType")
    public ResultDto projectType() {
        return ResultDto.ok(projectManagerService.projectType());
    }
    /**
     * 公司类型
     */
    @GetMapping("/companyType")
    public ResultDto companyType() {
        return ResultDto.ok(projectManagerService.companyType());
    }
    /**
     * 查询项目名称是否存在
     */
    @GetMapping("/selectByProjectName")
    public ResultDto selectByProjectName(@RequestParam String name) {
        return ResultDto.ok(projectManagerService.selectByProjectName(name));
    }
}